package de.fhkl.android.beans;

import java.io.Serializable;
import java.io.StringWriter;
import java.util.ArrayList;

import org.xmlpull.v1.XmlSerializer;

import android.util.Xml;

public class MensaBean implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public static final int DAYS_IN_A_WEAK = 5;
	public ArrayList<DayMenu> menuList = new ArrayList<DayMenu>(5);
	private String namespace = "";

	public MensaBean() {
//		for (int i = 0; i < DAYS_IN_A_WEAK; i++) {
//			menus.add(new DayMenu());
//		}
	}

	public void setDate(ArrayList<String> contentList){
		if (contentList.size()==DAYS_IN_A_WEAK){
			for (int i=0;i<DAYS_IN_A_WEAK;i++){
				menuList.get(i).setDate(contentList.get(i));
			}
		}
	}
	
	public void setMenu1(ArrayList<String> contentList){
		if (contentList.size()==DAYS_IN_A_WEAK){
			for (int i=0;i<DAYS_IN_A_WEAK;i++){
				menuList.get(i).setMenu1(contentList.get(i));
			}
		}
	}
	
	public void setMenu2(ArrayList<String> contentList){
		if (contentList.size()==DAYS_IN_A_WEAK){
			for (int i=0;i<DAYS_IN_A_WEAK;i++){
				menuList.get(i).setMenu2(contentList.get(i));
			}
		}
	}
	public String toString() {
		XmlSerializer serializer = Xml.newSerializer();
		StringWriter writer = new StringWriter();
		try {
			serializer.setOutput(writer);
			serializer.startDocument("UTF-8", true);

			serializer.startTag(namespace, "mensa");
			for (int i = 0; i < menuList.size(); i++) {
				serializer.startTag(namespace, "day");

				serializer.startTag(namespace, "date");
				serializer.text(menuList.get(i).getDate());
				serializer.endTag(namespace, "date");

				serializer.startTag(namespace, "menu1");
				serializer.text(menuList.get(i).getMenu1());
				serializer.endTag(namespace, "menu1");

				serializer.startTag(namespace, "menu2");
				serializer.text(menuList.get(i).getMenu1());
				serializer.endTag(namespace, "menu2");

				serializer.endTag(namespace, "day");
			}
			serializer.endTag(namespace, "mensa");

			serializer.endDocument();

			return writer.toString();
		} catch (Exception e) {
			throw new RuntimeException(e);
		}

	}
}


